//获取本地信息
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var self;
var title;
var partition_type;
//下拉刷新
mui.init()
var mask = mui.createMask(); //遮罩层
//所属区域商品集合
function itemPartitionList() {
	mui.ajax(goods_url + '/goods/zitemGiftList', {
		data: {
			"gift_type": gift_id,
			"partition_type": partition_type,
			"phone": my_phone,
			"sign": "string",
			"user_id": user_id
		},
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		headers: {
			'Content-Type': 'application/json'
		},
		success: function(data) {
			if(data.code == 10000) {
				var html = '';
				if(data.resp.length > 0) {
					for(var i = 0; i < data.resp.length; i++) {
						html += '<li class="mui-col-xs-6 mui-col-sm-6 product_color product_jump_con" commodity_id="' + data.resp[i].id + '">';
						html += '<div class="product_img">';
						html += '<img width="100%" height="100%" class="lazy" data-original="' + data.resp[i].url + data.resp[i].image + '"/>';
						html += '</div>';
						html += '<p class="product_name">' + data.resp[i].title + '</p>';
						html += '<p class="product_num">￥' + data.resp[i].price + '</p>';
						html += '<div class="dealer">';
						if(data.resp[i].sales_volume == null) {
							html += '<p>销量 0</p>';
						} else {
							html += '<p>销量 ' + data.resp[i].sales_volume + '</p>';
						}
						if(data.resp[i].commercial == 1) {
							html += '<span class="dealer_icon">自营</span>';
						} else if(data.resp[i].commercial == 2) {
							html += '<span class="dealer_icon">商家</span>';
						}
						html += '</div>';
						html += '</li>';
					}
					$('.product_details').html(html);
					$("img.lazy").lazyload({
						effect: "fadeIn",
						placeholder: "../../images/as.jpg",
						container: $(".product_details"),
						failurelimit: 10
					});
				} else {
					$('.product_details').html('<div style="line-height:200px;color:#CCCCCC;text-align: center;">暂无礼包信息</div>');
				}

			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
		}
	});

}

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		self = plus.webview.currentWebview();
		gift_id = self.gift_id;
		partition_type = self.partition_type;
		title = self.title;
		$(".mui-title").text(title);
		itemPartitionList()
		plus.nativeUI.closeWaiting(); //关闭等待
	})
}

/*mui('.mui-scroll-wrapper').scroll({
	deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值 0.0006 
	indicators: true //隐藏一条滚动条 增大减速系数。。。
});*/

//商品详情
mui("body").on("tap", ".product_jump_con", function() {
	var commodity_id = $(this).attr('commodity_id');
	mui.openWindow({
		url: "commodity_details.html",
		extras: {
			commodity_id: commodity_id
		},
		createNew: true
	})
});

//判断ios
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if(isiOS) {
	$(".mui-scroll-wrapper").css("padding-top", "50px")
}